home *** CD-ROM | disk | FTP | other *** search
/ Workbench Add-On / Workbench Add-On - Volume 1.iso / BBS-Archive / Dev / ace23.lha / PRGS.lha / Misc / linkedlist.b < prev   
Text File  |  1994-10-15  |  787b  |  49 lines

  1. '..a linked list using ACE structures.
  2.  
  3. DEFLNG a-z
  4.  
  5. STRUCT node
  6.  STRING nm
  7.  ADDRESS nxt
  8. END STRUCT
  9.  
  10. DECLARE STRUCT node *head,*new.item,*curr,*temp
  11.  
  12. SUB make.node
  13.  make.node = ALLOC(SIZEOF(node))
  14. END SUB
  15.  
  16. '..create head of list
  17. head = make.node
  18. IF head = NULL THEN
  19.   PRINT "head node can't be allocated!"
  20.   STOP
  21. END IF
  22.  
  23. head->nm = ""
  24. head->nxt = NULL
  25. curr = head
  26.  
  27. '..create list
  28. REPEAT
  29.  INPUT "type a name (or QUIT): ";x$
  30.  new.item = make.node
  31.  IF new.item <> NULL THEN
  32.   new.item->nm = x$
  33.   new.item->nxt = NULL
  34.  
  35.   curr->nxt = new.item
  36.   curr = curr->nxt
  37.  ELSE
  38.   PRINT "new node can't be allocated!"
  39.  END IF
  40. UNTIL UCASE$(x$) = "QUIT" OR new.item=NULL
  41.  
  42. '..traverse list
  43. CLS
  44. curr = head->nxt
  45. WHILE curr <> NULL
  46.   IF UCASE$(curr->nm) <> "QUIT"  THEN PRINT curr->nm
  47.   curr = curr->nxt
  48. WEND
  49.